import 'package:elephant_fish/model/user.dart';
import 'package:elephant_fish/util/size_util.dart';
import 'package:elephant_fish/widget/welfare_center_list.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class WelfareCenterPage extends StatefulWidget {
  const WelfareCenterPage({Key key}) : super(key: key);

  @override
  _WelfareCenterPageState createState() => _WelfareCenterPageState();
}

class _WelfareCenterPageState extends State<WelfareCenterPage> {
  List<User> userList = [];
  bool _loading = false;
  ScrollController _scrollController = ScrollController();
  @override
  void initState() {
    super.initState();
    _scrollController.addListener(() {
      var dis = _scrollController.position.maxScrollExtent -
          _scrollController.position.pixels;
      //当距离底部不足300时加载更多
      if (dis < 300 && !_loading) {
        _loadData(loadMore: true);
      }
    });
    _loadData();
  }


  @override
  void dispose() {
    super.dispose();
    _scrollController.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xff140c3d),
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: Color(0xff140c3d),
        leading: GestureDetector(
          child: Icon(
            Icons.arrow_back_ios,size: SizeUtil.px(32),color: Color(0xffffffff),
          ),
          onTap: (){
            Navigator.pop(context);
          },
        ),
        title: Text('福利中心',style: TextStyle(fontSize: SizeUtil.px(32),color: Color(0xffffffff)),),
        actions: [
          Align(
            alignment: Alignment.centerRight,
            child: Padding(
              padding: EdgeInsets.only(right: SizeUtil.px(32)),
              child: InkWell(
                child: Icon(Icons.help_outline,size: SizeUtil.px(40),color: Color(0xffffffff),),
                onTap: (){

                },
              ),
            )
          )
        ],
      ),
      body: Column(
        children: [
          Expanded(child: ListView.builder(
              itemCount: userList.length,
              controller: _scrollController,
              shrinkWrap: true,
              itemBuilder:(context,index){
                return WelfareCenterList();
              }
          ),),
          SizedBox(height: SizeUtil.px(30),),
          Align(
            alignment: Alignment.center,
            child: Container(
              width: SizeUtil.px(517),
              height: SizeUtil.px(73),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.all(Radius.circular(SizeUtil.px(43))),
                color: Color(0xffe62d6c),
              ),
              child: Align(
                alignment: Alignment.center,
                child: Text(
                  '立即邀请',textAlign: TextAlign.center,style: TextStyle(fontSize: SizeUtil.px(28),color: Color(0xfff3f3f3)),
                ),
              )
            ),
          ),
          SizedBox(height: SizeUtil.px(60),),
        ],
      )


    );
  }

  _loadData({loadMore = false})async{
    for(int i = 0 ; i < 30;i++){
      User user = User(10000+i, '张三' + i.toString() ,'https://img1.baidu.com/it/u=729283109,1369002854&fm=26&fmt=auto&gp=0.jpg',156,468,'456456465');
      userList.add(user);

    }
  }
}
